//package com.plian.system.service.transfer.impl;
//
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.plian.Tools.*;
//import com.plian.system.entity.hr.dept.Dept;
//import com.plian.system.entity.hr.staff.*;
//import com.plian.system.entity.sys.FormHistoryRecord;
//import com.plian.system.entity.sys.Org;
//import com.plian.system.model.R;
//import com.plian.system.service.hr.dept.IDeptService;
//import com.plian.system.service.hr.staff.*;
//import com.plian.system.service.sys.orgzation.IOrgService;
//import com.plian.system.service.sys.system.IFormHistoryRecordService;
//import com.plian.system.service.transfer.IStaffFilesTransferService;
//import com.plian.system.vo.hr.dept.DeptVO;
//import com.plian.system.vo.hr.staff.*;
//import com.plian.system.wrapper.hr.dept.DeptWrapper;
//import com.plian.system.wrapper.hr.staff.*;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.stream.Collectors;
//import java.util.stream.Stream;
//
//import static com.plian.system.constant.sys.BaseConstant.BASE64_KEY;
//import static com.plian.system.constant.sys.FormStatusConstant.UNREVIEWED;
//import static com.plian.system.constant.sys.FormTypeConstant.*;
//
//@Slf4j
//@Service
//@AllArgsConstructor
//public class StaffFilesTransferServiceImpl implements IStaffFilesTransferService {
//
//    private IDeptService deptService;
//    private IStaffFilesService staffFilesService;
//    private IOrgService orgService;
//    private StaffFilesWrapper staffFilesWrapper;
//    private IAppointRemoveService appointRemoveService;
//    private IEducationDegreeService educationDegreeService;
//    private IWorkExperienceService workExperienceService;
//    private IRewardsPunishmentsService rewardsPunishmentsService;
//    private IAnnualAssessmentService annualAssessmentService;
//    private ISocialRelationsService socialRelationsService;
//    private IPractitionerCertificateService practitionerCertificateService;
//    private ITechnicalQualificationService technicalQualificationService;
//    private ITrainService trainService;
//    private IOverseasMembersService overseasMembersService;
//    private IFormHistoryRecordService formHistoryRecordService;
//
//    private IDirectorService directorService;
//
//    private DirectorWrapper directorWrapper;
//
//    private ISupervisorService supervisorService;
//
//    private SupervisorWrapper supervisorWrapper;
//
//    private DeptWrapper deptWrapper;
//
//    private TechnicalQualificationWrapper technicalQualificationWrapper;
//
//    private EducationDegreeWrapper educationDegreeWrapper;
//
//    private PractitionerCertificateWrapper practitionerCertificateWrapper;
//
//    @Override
//    @Transactional(rollbackFor = RuntimeException.class)
//    public R submitList(List<StaffFilesVO> staffFilesVOS) {
//        List<StaffFiles> allList = staffFilesService.list();
//        Map<String, StaffFiles> allMap = allList.stream()
//                .collect(Collectors.toMap(staffFiles -> staffFiles.getCompanyNameId() + StringPool.UNDERSCORE
//                                + EncryptUtil.decryptBase64(staffFiles.getStaffCode(), BASE64_KEY), staffFiles -> staffFiles));
//        List<Org> allOrg = orgService.getAllChild(TokenUtil.getTokenOrgId());
//        Map<String, Org> orgNameMap = allOrg.stream().collect(Collectors.toMap(Org::getName, org -> org));
//        String tokenUserId = TokenUtil.getTokenUserId();
//
//        List<Dept> deptList = deptService.list();
//        Map<String, Dept> deptMap = deptList.stream()
//                .collect(Collectors.toMap(dept -> dept.getDeptAffiliation() + StringPool.UNDERSCORE + dept.getDeptName(), dept -> dept));
//
//        ObjectMapper mapper=new ObjectMapper();
//        List<FormHistoryRecord> recordList = new ArrayList<>();
//        List<Long> updateIds = new ArrayList<>();
//
//        List<EducationDegree>  educationDegreeList = new ArrayList<>();
//        List<AppointRemove>  appointRemoveList = new ArrayList<>();
//        List<WorkExperience>  workExperienceList = new ArrayList<>();
//        List<RewardsPunishments>  rewardsPunishmentsList = new ArrayList<>();
//        List<AnnualAssessment>  annualAssessmentList = new ArrayList<>();
//        List<SocialRelations>  socialRelationsList = new ArrayList<>();
//        List<PractitionerCertificate>  practitionerCertificateList = new ArrayList<>();
//        List<TechnicalQualification>  technicalQualificationList = new ArrayList<>();
//        List<Train> trainList = new ArrayList<>();
//        List<OverseasMembers>  overseasMembersList = new ArrayList<>();
//
//        List<String> messages = new ArrayList<>();
//        List<String> documentNumbers = new ArrayList<>();
//        for (StaffFilesVO staffFilesVO : staffFilesVOS){
//            if (!orgNameMap.containsKey(staffFilesVO.getCompanyName())){
//                messages.add(staffFilesVO.getStaffName() + StringPool.UNDERSCORE + staffFilesVO.getCompanyName());
//                continue;
//            }
//            if (documentNumbers.contains(staffFilesVO.getDocumentNumber())){
//                continue;
//            }
//            documentNumbers.add(staffFilesVO.getDocumentNumber());
//            staffFilesVO.setDataSource(tokenUserId);
//            staffFilesVO.setStatus(UNREVIEWED);
//            staffFilesVO.setStaffCode(staffFilesVO.getDocumentNumber());
//            staffFilesVO.setFormType(String.valueOf(HR_STAFFFILES_FORM));
//            if (!(staffFilesVO.getDef18() != null && staffFilesVO.getDef18() == 2L)){
//                staffFilesVO.setDef18(1L);
//            }
//            staffFilesVO.setIsDeleted(0);
//            staffFilesVO.setCompanyNameId(orgNameMap.get(staffFilesVO.getCompanyName()).getId());
//            staffFilesVO.setCreateCompanyId(staffFilesVO.getCompanyNameId());
//
//            String deptKey = staffFilesVO.getCompanyNameId() + StringPool.UNDERSCORE + staffFilesVO.getDepartmentName();
//            if (deptMap.containsKey(deptKey)){
//                Dept dept = deptMap.get(deptKey);
//                staffFilesVO.setDepartmentNameId(String.valueOf(dept.getId()));
//                staffFilesVO.setDepartmentCode(dept.getDeptCode());
//            }
//            String key = staffFilesVO.getCompanyNameId() + StringPool.UNDERSCORE + staffFilesVO.getDocumentNumber();
//            if (allMap.containsKey(key)){
//                StaffFiles old = allMap.get(key);
//                updateIds.add(old.getId());
//                staffFilesVO.setId(old.getId());
//                StaffFilesVO oldVO = staffFilesWrapper.entityToVO(old);
//                boolean sameFlag = staffFilesService.isSame(staffFilesVO, oldVO);
//                if (!sameFlag){
//                    try {
//                        recordList.add(FormHistoryRecord.builder().formType(String.valueOf(HR_STAFFFILES_FORM))
//                                .record(mapper.writeValueAsString(oldVO)).recordId(staffFilesVO.getId()).build());
//                    }catch (Exception e){
//                        log.error("员工档案--> 历史数据版本保存失败");
//                    }
//                }
//            }
//
//            staffFilesService.encryptBase64Data(staffFilesVO);
//            StaffFiles staffFiles = staffFilesWrapper.voToEntity(staffFilesVO);
//            staffFilesService.saveOrUpdate(staffFiles);
//
//            List<EducationDegreeVO> educationDegreeVOS = staffFilesVO.getEducationDegreeVO();
//            if (CollectionUtil.isNotEmpty(educationDegreeVOS)){
//                for (EducationDegreeVO one : educationDegreeVOS) {
//                    one.setStaffFilesId(staffFiles.getId());
//                    educationDegreeList.add(one);
//                }
//            }
//
//            //任免记录
//            List<AppointRemoveVO> appointRemoveVO = staffFilesVO.getAppointRemoveVO();
//            if(CollectionUtil.isNotEmpty(appointRemoveVO)) {
//                for (AppointRemoveVO one : appointRemoveVO) {
//                    one.setStaffFilesId(staffFiles.getId());
//                    appointRemoveList.add(one);
//                }
//            }
//            //工作经历
//            List<WorkExperienceVO> workExperienceVO = staffFilesVO.getWorkExperienceVO();
//            if(CollectionUtil.isNotEmpty(workExperienceVO)) {
//                for (WorkExperienceVO one : workExperienceVO) {
//                    one.setStaffFilesId(staffFiles.getId());
//                    workExperienceList.add(one);
//                }
//            }
//            //奖惩情况
//            List<RewardsPunishmentsVO> rewardsPunishmentsVO = staffFilesVO.getRewardsPunishmentsVO();
//            if(CollectionUtil.isNotEmpty(rewardsPunishmentsVO)) {
//                for (RewardsPunishmentsVO one : rewardsPunishmentsVO) {
//                    one.setStaffFilesId(staffFiles.getId());
//                    rewardsPunishmentsList.add(one);
//                }
//            }
//            //年度考核结果
//            List<AnnualAssessmentVO> annualAssessmentVO = staffFilesVO.getAnnualAssessmentVO();
//            if(CollectionUtil.isNotEmpty(annualAssessmentVO)) {
//                for (AnnualAssessmentVO one : annualAssessmentVO) {
//                    one.setStaffFilesId(staffFiles.getId());
//                    annualAssessmentList.add(one);
//                }
//            }
//            //家庭及社会关系
//            List<SocialRelationsVO> socialRelationsVO = staffFilesVO.getSocialRelationsVO();
//            if(CollectionUtil.isNotEmpty(socialRelationsVO)) {
//                for (SocialRelationsVO one : socialRelationsVO) {
//                    one.setStaffFilesId(staffFiles.getId());
//                    socialRelationsList.add(one);
//                }
//            }
//            //从业资格证书
//            List<PractitionerCertificateVO> practitionerCertificateVO = staffFilesVO.getPractitionerCertificateVO();
//            if(CollectionUtil.isNotEmpty(practitionerCertificateVO)) {
//                for (PractitionerCertificateVO one : practitionerCertificateVO) {
//                    one.setStaffFilesId(staffFiles.getId());
//                    practitionerCertificateList.add(one);
//                }
//            }
//            //专业技术资格
//            List<TechnicalQualificationVO> technicalQualificationVO = staffFilesVO.getTechnicalQualificationVO();
//            if(CollectionUtil.isNotEmpty(technicalQualificationVO)) {
//                for (TechnicalQualificationVO one : technicalQualificationVO) {
//                    one.setStaffFilesId(staffFiles.getId());
//                    technicalQualificationList.add(one);
//                }
//            }
//            List<TrainVO> trainVO = staffFilesVO.getTrainVO();
//            if(CollectionUtil.isNotEmpty(trainVO)) {
//                for (TrainVO one : trainVO) {
//                    one.setStaffFilesId(staffFiles.getId());
//                    trainList.add(one);
//                }
//            }
//            List<OverseasMembersVO> overseasMembersVO = staffFilesVO.getOverseasMembersVO();
//            if(CollectionUtil.isNotEmpty(overseasMembersVO)) {
//                for (OverseasMembersVO one : overseasMembersVO) {
//                    one.setStaffFilesId(staffFiles.getId());
//                    overseasMembersList.add(one);
//                }
//            }
//        }
//
//        if (CollectionUtil.isNotEmpty(updateIds)){
//            educationDegreeService.remove(new LambdaQueryWrapper<EducationDegree>().in(EducationDegree::getStaffFilesId, updateIds));
//        }
//        if (CollectionUtil.isNotEmpty(educationDegreeList)){
//            educationDegreeService.saveList(educationDegreeList);
//        }
//        if (CollectionUtil.isNotEmpty(updateIds)){
//            appointRemoveService.remove(new LambdaQueryWrapper<AppointRemove>().in(AppointRemove::getStaffFilesId, updateIds));
//        }
//        if (CollectionUtil.isNotEmpty(appointRemoveList)){
//            appointRemoveService.saveList(appointRemoveList);
//        }
//        if (CollectionUtil.isNotEmpty(updateIds)){
//            workExperienceService.remove(new LambdaQueryWrapper<WorkExperience>().in(WorkExperience::getStaffFilesId, updateIds));
//        }
//        if (CollectionUtil.isNotEmpty(workExperienceList)){
//            workExperienceService.saveList(workExperienceList);
//        }
//        if (CollectionUtil.isNotEmpty(updateIds)){
//            rewardsPunishmentsService.remove(new LambdaQueryWrapper<RewardsPunishments>().in(RewardsPunishments::getStaffFilesId, updateIds));
//        }
//        if (CollectionUtil.isNotEmpty(rewardsPunishmentsList)){
//            rewardsPunishmentsService.saveList(rewardsPunishmentsList);
//        }
//        if (CollectionUtil.isNotEmpty(updateIds)){
//            annualAssessmentService.remove(new LambdaQueryWrapper<AnnualAssessment>().in(AnnualAssessment::getStaffFilesId, updateIds));
//        }
//        if (CollectionUtil.isNotEmpty(annualAssessmentList)){
//            annualAssessmentService.saveList(annualAssessmentList);
//        }
//        if (CollectionUtil.isNotEmpty(updateIds)){
//            socialRelationsService.remove(new LambdaQueryWrapper<SocialRelations>().in(SocialRelations::getStaffFilesId, updateIds));
//        }
//        if (CollectionUtil.isNotEmpty(socialRelationsList)){
//            socialRelationsService.saveList(socialRelationsList);
//        }
//        if (CollectionUtil.isNotEmpty(updateIds)){
//            practitionerCertificateService.remove(new LambdaQueryWrapper<PractitionerCertificate>().in(PractitionerCertificate::getStaffFilesId, updateIds));
//        }
//        if (CollectionUtil.isNotEmpty(practitionerCertificateList)){
//            practitionerCertificateService.saveList(practitionerCertificateList);
//        }
//        if (CollectionUtil.isNotEmpty(updateIds)){
//            technicalQualificationService.remove(new LambdaQueryWrapper<TechnicalQualification>().in(TechnicalQualification::getStaffFilesId, updateIds));
//        }
//        if (CollectionUtil.isNotEmpty(technicalQualificationList)){
//            technicalQualificationService.saveList(technicalQualificationList);
//        }
//        if (CollectionUtil.isNotEmpty(updateIds)){
//            trainService.remove(new LambdaQueryWrapper<Train>().in(Train::getStaffFilesId, updateIds));
//        }
//        if (CollectionUtil.isNotEmpty(trainList)){
//            trainService.saveList(trainList);
//        }
//        if (CollectionUtil.isNotEmpty(updateIds)){
//            overseasMembersService.remove(new LambdaQueryWrapper<OverseasMembers>().in(OverseasMembers::getStaffFilesId, updateIds));
//        }
//        if (CollectionUtil.isNotEmpty(overseasMembersList)){
//            overseasMembersService.saveList(overseasMembersList);
//        }
//
//        if (CollectionUtil.isNotEmpty(recordList)){
//            for (FormHistoryRecord formHistoryRecord : recordList){
//                formHistoryRecordService.submit(formHistoryRecord);
//            }
//        }
//
//        if (CollectionUtil.isNotEmpty(messages)){
//            return R.data(messages.stream().collect(Collectors.joining(StringPool.COMMA)) + "单位不存在");
//        }
//        return R.success();
//    }
//
//    @Override
//    @Transactional(rollbackFor = RuntimeException.class)
//    public R submitDirectorList(List<DirectorVO> directorVOS) {
//        String tokenUserId = TokenUtil.getTokenUserId();
//        List<StaffFiles> allList = staffFilesService
//                .list(new LambdaQueryWrapper<StaffFiles>().eq(StaffFiles::getDataSource, tokenUserId));
//        if (CollectionUtil.isEmpty(allList)){
//            return R.fail("员工数据为空，董事会更新失败！");
//        }
//        Map<String, StaffFiles> staffFilesMap = allList.stream()
//                .collect(Collectors.toMap(StaffFiles::getDataSourceId, staffFiles -> staffFiles));
//
//        List<Director> allOldDirectors = directorService.list();
//        Map<Long, Director> directorMap = allOldDirectors.stream()
//                .filter(director -> director.getStaffFilesId() != null)
//                .collect(Collectors.toMap(Director::getStaffFilesId, director -> director));
//        List<Director> transferDirectors = directorService.list(Wrappers.<Director>lambdaQuery().eq(Director::getDataSource, tokenUserId));
//        Map<String, Director> transferdDirectorMap = transferDirectors.stream()
//                .filter(director -> director.getDataSourceId() != null)
//                .collect(Collectors.toMap(Director::getDataSourceId, director -> director));
//
//        List<Org> allOrg = orgService.getAllChild(TokenUtil.getTokenOrgId());
//        Map<String, Org> orgNameMap = allOrg.stream().collect(Collectors.toMap(Org::getName, org -> org));
//
//        List<String> messages = new ArrayList<>();
//        List<String> companyMessages = new ArrayList<>();
//        for (DirectorVO directorVO : directorVOS){
//            if (!orgNameMap.containsKey(directorVO.getCompanyName())){
//                companyMessages.add(directorVO.getStaffName() + StringPool.UNDERSCORE + directorVO.getCompanyName());
//                continue;
//            }
//
//            if (transferdDirectorMap.containsKey(directorVO.getDataSourceId())){
//                directorVO.setId(transferdDirectorMap.get(directorVO.getDataSourceId()).getId());
//                if (directorVO.getIsDeleted() != null && directorVO.getIsDeleted() == 1){
//                    directorService.deleteLogic(Stream.of(directorVO.getId()).collect(Collectors.toList()));
//                    continue;
//                }
//            }
//
//            if (directorVO.getIsOutDirector() != null && directorVO.getIsOutDirector() == 2){
//                directorVO.setCompanyId(orgNameMap.get(directorVO.getCompanyName()).getId());
//                directorVO.setCreateCompanyId(directorVO.getCompanyId());
//                directorVO.setDataSource(tokenUserId);
//                directorVO.setStatus(UNREVIEWED);
//                directorVO.setFormType(String.valueOf(HR_DIRECTOR_FORM));
//                if (directorVO.getIsDeleted() == null){
//                    directorVO.setIsDeleted(0);
//                }
//                if (StringUtil.isNotBlank(directorVO.getDocumentNumber())){
//                    directorVO.setDocumentNumber(EncryptUtil.encryptBase64(directorVO.getDocumentNumber(), BASE64_KEY));
//                }
//                directorService.saveOrUpdate(directorWrapper.voToEntity(directorVO));
//                continue;
//            }
//            if (!staffFilesMap.containsKey(directorVO.getDataSourceStaffFilesId())){
//                messages.add(directorVO.getStaffName() + StringPool.UNDERSCORE + directorVO.getDataSourceStaffFilesId());
//                continue;
//            }
//
//            StaffFiles staffFiles = staffFilesMap.get(directorVO.getDataSourceStaffFilesId());
//            directorVO.setStaffFilesId(staffFiles.getId());
//            directorVO.setCompanyId(staffFiles.getCompanyNameId());
//            directorVO.setStaffName(staffFiles.getStaffName());
//            directorVO.setGenderId(staffFiles.getGenderId());
//            directorVO.setBirthday(staffFiles.getBirthday());
//            directorVO.setPoliticCountenanceId(staffFiles.getPoliticCountenanceId());
//            directorVO.setEducationalId(staffFiles.getEducationalId());
//            directorVO.setDocumentNumber(staffFiles.getDocumentNumber());
//            directorVO.setNativePlace(staffFiles.getNativePlace());
//            directorVO.setTelephone(staffFiles.getTelephone());
//            directorVO.setFamilyAddress(staffFiles.getFamilyAddress());
////            directorVO.setAppointmentTime(staffFiles.getCompanyInitiationTime());
//            if (directorMap.containsKey(directorVO.getStaffFilesId())){
//                directorVO.setId(directorMap.get(directorVO.getStaffFilesId()).getId());
//                if (directorVO.getIsDeleted() != null && directorVO.getIsDeleted() == 1){
//                    directorService.deleteLogic(Stream.of(directorVO.getId()).collect(Collectors.toList()));
//                    continue;
//                }
//            }
//            directorVO.setCompanyId(orgNameMap.get(directorVO.getCompanyName()).getId());
//            directorVO.setCreateCompanyId(directorVO.getCompanyId());
//
//            directorVO.setDataSource(tokenUserId);
//            directorVO.setStatus(UNREVIEWED);
//            directorVO.setFormType(String.valueOf(HR_DIRECTOR_FORM));
//            directorVO.setIsDeleted(0);
//            directorService.saveOrUpdate(directorWrapper.voToEntity(directorVO));
//        }
//
//        String resultsMessage = "";
//        if (CollectionUtil.isNotEmpty(messages)){
//            resultsMessage += messages.stream().collect(Collectors.joining(StringPool.COMMA)) + "员工档案不存在;";
//        }
//        if (CollectionUtil.isNotEmpty(companyMessages)){
//            resultsMessage += companyMessages.stream().collect(Collectors.joining(StringPool.COMMA)) + "单位不存在";
//        }
//        return R.data(resultsMessage);
//    }
//
//    @Override
//    @Transactional(rollbackFor = RuntimeException.class)
//    public R submitSupervisorList(List<SupervisorVO> supervisorVOS) {
//        String tokenUserId = TokenUtil.getTokenUserId();
//        List<StaffFiles> allList = staffFilesService
//                .list(new LambdaQueryWrapper<StaffFiles>().eq(StaffFiles::getDataSource, tokenUserId));
//        if (CollectionUtil.isEmpty(allList)){
//            return R.fail("员工数据为空，监事会更新失败！");
//
//        }
//        Map<String, StaffFiles> staffFilesMap = allList.stream()
//                .collect(Collectors.toMap(StaffFiles::getDataSourceId, staffFiles -> staffFiles));
//
//        List<Supervisor> allOldSupervisors = supervisorService.list();
//        Map<Long, Supervisor> supervisorMap = allOldSupervisors.stream()
//                .filter(supervisor -> supervisor.getStaffFilesId() != null)
//                .collect(Collectors.toMap(Supervisor::getStaffFilesId, supervisor -> supervisor));
//
//        List<Org> allOrg = orgService.getAllChild(TokenUtil.getTokenOrgId());
//        Map<String, Org> orgNameMap = allOrg.stream().collect(Collectors.toMap(Org::getName, org -> org));
//
//        List<String> messages = new ArrayList<>();
//        List<String> companyMessages = new ArrayList<>();
//        for (SupervisorVO supervisorVO : supervisorVOS){
//            if (!staffFilesMap.containsKey(supervisorVO.getDataSourceStaffFilesId())){
//                messages.add(supervisorVO.getStaffName() + StringPool.UNDERSCORE + supervisorVO.getDataSourceStaffFilesId());
//                continue;
//            }
//
//            if (!orgNameMap.containsKey(supervisorVO.getCompanyName())){
//                companyMessages.add(supervisorVO.getStaffName() + StringPool.UNDERSCORE + supervisorVO.getCompanyName());
//                continue;
//            }
//            StaffFiles staffFiles = staffFilesMap.get(supervisorVO.getDataSourceStaffFilesId());
//            supervisorVO.setStaffFilesId(staffFiles.getId());
//            supervisorVO.setCompanyId(staffFiles.getCompanyNameId());
//            supervisorVO.setStaffName(staffFiles.getStaffName());
//            supervisorVO.setGenderId(staffFiles.getGenderId());
//            supervisorVO.setBirthday(staffFiles.getBirthday());
////            supervisorVO.setAppointmentTime(staffFiles.getCompanyInitiationTime());
//            supervisorVO.setStaffFilesId(staffFilesMap.get(supervisorVO.getDataSourceStaffFilesId()).getId());
//            if (supervisorMap.containsKey(supervisorVO.getStaffFilesId())){
//                supervisorVO.setId(supervisorMap.get(supervisorVO.getStaffFilesId()).getId());
//                if (supervisorVO.getIsDeleted() != null && supervisorVO.getIsDeleted() == 1){
//                    supervisorService.deleteLogic(Stream.of(supervisorVO.getId()).collect(Collectors.toList()));
//                    continue;
//                }
//            }
//            supervisorVO.setCompanyId(orgNameMap.get(supervisorVO.getCompanyName()).getId());
//            supervisorVO.setCreateCompanyId(supervisorVO.getCompanyId());
//
//            supervisorVO.setDataSource(tokenUserId);
//            supervisorVO.setStatus(UNREVIEWED);
//            supervisorVO.setFormType(String.valueOf(HR_SUPERVISOR_FORM));
//            if (supervisorVO.getIsDeleted() == null){
//                supervisorVO.setIsDeleted(0);
//            }
//            supervisorService.saveOrUpdate(supervisorWrapper.voToEntity(supervisorVO));
//        }
//
//        String resultsMessage = "";
//        if (CollectionUtil.isNotEmpty(messages)){
//            resultsMessage += messages.stream().collect(Collectors.joining(StringPool.COMMA)) + "员工档案不存在;";
//        }
//        if (CollectionUtil.isNotEmpty(companyMessages)){
//            resultsMessage += companyMessages.stream().collect(Collectors.joining(StringPool.COMMA)) + "单位不存在";
//        }
//        return R.data(resultsMessage);
//    }
//
//    @Override
//    public R submitDeptList(List<DeptVO> deptVOS) {
//        if (CollectionUtil.isEmpty(deptVOS)){
//            return R.success();
//        }
//        String tokenUserId = TokenUtil.getTokenUserId();
//        String tokenOrgId = TokenUtil.getTokenOrgId();
//        List<Org> allOrg = orgService.getAllChild(tokenOrgId);
//        Map<String, Org> orgNameMap = allOrg.stream().collect(Collectors.toMap(Org::getName, org -> org));
//        List<String> childOrgIds = allOrg.stream().map(Org::getId).collect(Collectors.toList());
//        List<Dept> existDeptList = deptService.list(Wrappers.<Dept>lambdaQuery().in(Dept::getDeptAffiliation, childOrgIds));
//        Map<String, Dept> existDeptMap = existDeptList.stream().collect(Collectors
//                .toMap(dept -> dept.getDeptAffiliation() + StringPool.UNDERSCORE + dept.getDeptName(), dept -> dept));
//        List<StaffFiles> staffFilesList = staffFilesService.list(Wrappers.<StaffFiles>lambdaQuery().in(StaffFiles::getCompanyNameId, childOrgIds));
//        Map<String, StaffFiles> staffFilesMap = staffFilesList.stream()
//                .collect(Collectors.toMap(staffFiles -> staffFiles.getCompanyNameId() + StringPool.UNDERSCORE + staffFiles.getDocumentNumber(),
//                        staffFiles -> staffFiles));
//
//        List<String> companyMessages = new ArrayList<>();
//        List<Dept> updateList = new ArrayList<>();
//        List<String> addKeyList = new ArrayList<>();
//        Map<String, String> parentDeptInfoMap = new HashMap<>();
//        for (DeptVO deptVO : deptVOS){
//            if (!orgNameMap.containsKey(deptVO.getDeptAffiliationName())){
//                companyMessages.add(deptVO.getDeptName() + StringPool.UNDERSCORE + deptVO.getDeptAffiliationName());
//                continue;
//            }
//            deptVO.setDeptAffiliation(orgNameMap.get(deptVO.getDeptAffiliationName()).getId());
//            deptVO.setCreateCompanyId(deptVO.getDeptAffiliation());
//            String key = deptVO.getDeptAffiliation() + StringPool.UNDERSCORE + deptVO.getDeptName();
//            if (addKeyList.contains(key)){
//                continue;
//            }
//            addKeyList.add(key);
//            if (existDeptMap.containsKey(key)){
//                Dept oldDept = existDeptMap.get(key);
//                deptVO.setId(oldDept.getId());
//            }
//            deptVO.setDataSource(tokenUserId);
//            if (StringUtil.isNotBlank(deptVO.getDeptHeadDocumentNumber())){
//                String staffKey = deptVO.getDeptAffiliation() + StringPool.UNDERSCORE + deptVO.getDeptHeadDocumentNumber();
//                if (staffFilesMap.containsKey(staffKey)){
//                    deptVO.setDeptHead(staffFilesMap.get(staffKey).getId());
//                }
//            }
//
//            if (StringUtil.isNotBlank(deptVO.getBaseinfoDeptName())){
//                String parentDeptKey = deptVO.getDeptAffiliation() + StringPool.UNDERSCORE + deptVO.getBaseinfoDeptName();
//                parentDeptInfoMap.put(key, parentDeptKey);
//
//            }
//            updateList.add(deptWrapper.voToEntity(deptVO));
//        }
//        if (CollectionUtil.isNotEmpty(updateList)){
//            deptService.saveList(updateList);
//            if (CollectionUtil.isNotEmpty(parentDeptInfoMap)){
//                List<Dept> allDeptList = deptService.list(Wrappers.<Dept>lambdaQuery().in(Dept::getDeptAffiliation, childOrgIds));
//                Map<String, Dept> allDeptMap = allDeptList.stream().collect(Collectors
//                        .toMap(dept -> dept.getDeptAffiliation() + StringPool.UNDERSCORE + dept.getDeptName(), dept -> dept));
//                List<Dept> updateParentList = new ArrayList<>();
//                for (Dept dept : updateList){
//                    String key =  dept.getDeptAffiliation() + StringPool.UNDERSCORE + dept.getDeptName();
//                    if (parentDeptInfoMap.containsKey(key)){
//                        String parentDeptKey = parentDeptInfoMap.get(key);
//                        if (allDeptMap.containsKey(parentDeptKey)){
//                            dept.setDeptHigherId(allDeptMap.get(parentDeptKey).getId());
//                            updateParentList.add(dept);
//                        }
//                    }
//                }
//                if (CollectionUtil.isNotEmpty(updateParentList)){
//                    deptService.updateBatchById(updateParentList);
//                }
//            }
//
//
//        }
//        String resultsMessage = "";
//        if (CollectionUtil.isNotEmpty(companyMessages)){
//            resultsMessage += companyMessages.stream().collect(Collectors.joining(StringPool.COMMA)) + "单位不存在";
//        }
//        return R.data(resultsMessage);
//    }
//
//    @Override
//    public List<StaffFilesVO> staffFilesByOrgId(String orgId) {
//
//        List<String> allChildIds = orgService.getAllChildIds(orgId);
//        List<StaffFiles> staffFiles = staffFilesService.list(Wrappers.<StaffFiles>lambdaQuery()
//                .in(StaffFiles::getCompanyNameId, allChildIds)
//                .eq(StaffFiles::getIsOut, 1)
//                .eq(StaffFiles::getDef18, 1));
//        if (CollectionUtil.isEmpty(staffFiles)){
//            return new ArrayList<>();
//        }
//        List<Long> staffFilesIds = staffFiles.stream().map(StaffFiles::getId).collect(Collectors.toList());
//        List<EducationDegree> educationDegrees = educationDegreeService.list(Wrappers.<EducationDegree>lambdaQuery()
//                .in(EducationDegree::getStaffFilesId, staffFilesIds));
//        Map<Long, List<EducationDegreeVO>> educationDegreeMap = educationDegreeWrapper.entityToVO(educationDegrees)
//                .stream().collect(Collectors.groupingBy(EducationDegreeVO::getStaffFilesId));
//        List<TechnicalQualification> technicalQualifications = technicalQualificationService.list(Wrappers.<TechnicalQualification>lambdaQuery()
//                .in(TechnicalQualification::getStaffFilesId, staffFilesIds));
//        Map<Long, List<TechnicalQualificationVO>> technicalQualificationMap = technicalQualificationWrapper.entityToVO(technicalQualifications)
//                .stream().collect(Collectors.groupingBy(TechnicalQualificationVO::getStaffFilesId));
//        List<PractitionerCertificate> practitionerCertificates = practitionerCertificateService.list(Wrappers.<PractitionerCertificate>lambdaQuery()
//                .in(PractitionerCertificate::getStaffFilesId, staffFilesIds));
//        Map<Long, List<PractitionerCertificateVO>> practitionerCertificateMap = practitionerCertificateWrapper.entityToVO(practitionerCertificates)
//                .stream().collect(Collectors.groupingBy(PractitionerCertificateVO::getStaffFilesId));
//        List<StaffFilesVO> staffFilesVOS = staffFilesService.setVO(staffFiles);
//        for (StaffFilesVO staffFilesVO : staffFilesVOS){
//            if (educationDegreeMap.containsKey(staffFilesVO.getId())){
//                staffFilesVO.setEducationDegreeVO(educationDegreeMap.get(staffFilesVO.getId()));
//            }
//            if (technicalQualificationMap.containsKey(staffFilesVO.getId())){
//                staffFilesVO.setTechnicalQualificationVO(technicalQualificationMap.get(staffFilesVO.getId()));
//            }
//            if (practitionerCertificateMap.containsKey(staffFilesVO.getId())){
//                staffFilesVO.setPractitionerCertificateVO(practitionerCertificateMap.get(staffFilesVO.getId()));
//            }
//        }
//        return staffFilesVOS;
//    }
//}
